﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    class Logger
    {
        private readonly StreamWriter _streamWriter;

        public Logger()
        {
            _streamWriter = new StreamWriter("log.txt");

            Notification.BeginOperationEvent += OnBeginOperation;
            Notification.EndOperationEvent += OnEndOperation;
            Notification.FailOperationEvent += OnFailOperation;
            Notification.DebugMessageEvent += OnDebugMessage;
        }

        void OnBeginOperation(NodeOperationEventArgs e)
        {
            _streamWriter.WriteLine(DateTime.Now + " Started operation : ".PadLeft(Notification.Depth * 2 + 21) + e.Message);
            _streamWriter.Flush();
        }

        void OnEndOperation(NodeOperationEventArgs e)
        {
            _streamWriter.WriteLine(DateTime.Now + " Finished operation: ".PadLeft(Notification.Depth * 2 + 21) + e.Message);
            _streamWriter.Flush();
        }

        void OnFailOperation(NodeOperationEventArgs e)
        {
            _streamWriter.WriteLine(DateTime.Now + " Error: " + e.Message);
            _streamWriter.Flush();
        }

        void OnDebugMessage(NodeOperationEventArgs e)
        {
            _streamWriter.WriteLine(DateTime.Now + " Debug message     : ".PadLeft(Notification.Depth * 2 + 21) + e.Message);
            _streamWriter.Flush();
        }

        
    }
}
